/**
 * 1880. 检查某单词是否等于两单词之和
 * https://leetcode-cn.com/problems/check-if-word-equals-summation-of-two-words/
 */
public class Solutions_1880 {
    public static void main(String[] args) {
//        String firstWord = "acb", secondWord = "cba", targetWord = "cdb";  // output: true
//        String firstWord = "aaa", secondWord = "a", targetWord = "aab";  // output: false
        String firstWord = "aaa", secondWord = "a", targetWord = "aaaa";  // output: true

        boolean result = isSumEqual(firstWord, secondWord, targetWord);
        System.out.println(result);
    }

    public static boolean isSumEqual(String firstWord, String secondWord, String targetWord) {
        int sum1 = 0;
        int sum2 = 0;
        int targetSum = 0;

        char[] arr1 = firstWord.toCharArray();
        char[] arr2 = secondWord.toCharArray();
        char[] arr3 = targetWord.toCharArray();

        for (char c : arr1) {
            sum1 *= 10;
            sum1 += c - 'a';
        }
        for (char c : arr2) {
            sum2 *= 10;
            sum2 += c - 'a';
        }
        for (char c : arr3) {
            targetSum *= 10;
            targetSum += c - 'a';
        }

        return (sum1 + sum2) == targetSum;
    }
}
